﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>WinSetStyle / WinSetExStyle - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The WinSetStyle and WinSetExStyle functions change the style or extended style of the specified window, respectively." />
<meta name="ahk:equiv-v1" content="commands/WinSet.htm#Style" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>WinSetStyle / WinSetExStyle</h1>

<p>Changes the style or extended style of the specified window, respectively.</p>

<pre class="Syntax"><span class="func">WinSetStyle</span> Value <span class="optional">, WinTitle, WinText, ExcludeTitle, ExcludeText</span>
<span class="func">WinSetExStyle</span> Value <span class="optional">, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h2 id="Parameters">参数</h2>
<dl>
    <dt>Value</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#numbers">整数</a>或<a href="../Concepts.htm#strings">字符串</a></p>
        <p>Pass a positive integer to completely overwrite the window's style; that is, to set it to <em>Value</em>.</p>
        <p>To easily add, remove or toggle styles, pass a numeric string prefixed with a plus sign (+), minus sign (-) or caret (^), respectively. The new style value is calculated as shown below (where CurrentStyle could be retrieved with <a href="WinGetStyle.htm">WinGetStyle/WinGetExStyle</a>):</p>
        <table class="info">
            <tr>
                <th>Operation</th>
                <th>Prefix</th>
                <th>Example String</th>
                <th>Formula</th>
            </tr>
            <tr>
                <td>Add</td>
                <td>+</td>
                <td>+0x80</td>
                <td><code>NewStyle := CurrentStyle | Value</code></td>
            </tr>
            <tr>
                <td>Remove</td>
                <td>-</td>
                <td>-0x80</td>
                <td><code>NewStyle := CurrentStyle &amp; ~Value</code></td>
            </tr>
            <tr>
                <td>Toggle</td>
                <td>^</td>
                <td>^0x80</td>
                <td><code>NewStyle := CurrentStyle ^ Value</code></td>
            </tr>
        </table>
        <p>If <em>Value</em> is a negative integer, it is treated the same as the corresponding numeric string.</p>
        <p>To use the + or ^ prefix literally in an expression, the prefix or value must be enclosed in quote marks. 例如: <code>WinSetStyle("+0x80")</code> or <code>WinSetStyle("^" StylesToToggle)</code>. This is because the <a href="../Variables.htm#Expressions">expression</a> <code><a href="../Variables.htm#unary">+123</a></code> produces 123 (without a prefix) and <code>^123</code> is a syntax error.</p>
    </dd>
    <dt>WinTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
        <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
    </dd>
    <dt>WinText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>如果存在, 此参数必须是目标窗口的单个文本元素的子字符串(和内置的 Window Spy 工具显示的一样). 如果 <a href="DetectHiddenText.htm">DetectHiddenText</a> 为 ON, 那么会检测隐藏文本元素.</p>
    </dd>
    <dt>ExcludeTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>标题中含有此参数值的窗口将被排除.</p>
    </dd>
    <dt>ExcludeText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>文本中含有此参数值的窗口将被排除.</p>
    </dd>
</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
<p>函数返回 1(true) 表示成功, 或 0(false) 表示失败.</p>

<h2 id="Error_Handling">错误处理</h2>
<p>如果遇到问题, <a href="../misc/ErrorLevel.htm">ErrorLevel</a> 设置为 1, 否则设置为 0. 如果找不到目标窗口或无法应用更改, 则失败.</p>

<h2 id="Remarks">备注</h2>
<p>See the <a href="../misc/Styles.htm">styles table</a> for a partial listing of styles.</p>
<p>After applying certain style changes to a visible window, it might be necessary to redraw the window using <a href="WinRedraw.htm">WinRedraw</a>.</p>
<p>鼠标光标下的窗口的 ID 可以使用 <a href="MouseGetPos.htm">MouseGetPos</a> 来获取.</p>
<p>窗口标题和文本是区分大小写的. 除非 <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> 被打开, 否则不会检测隐藏窗口.</p>

<h2 id="Related">相关</h2>
<p><a href="WinGetStyle.htm">WinGetStyle / WinGetExStyle</a>, <a href="ControlSetStyle.htm">ControlSetStyle / ControlSetExStyle</a>, <a href="../misc/Styles.htm">styles table</a>, <a href="Win.htm">Win functions</a>, <a href="Control.htm">Control functions</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExStyle">
<p><a href="#ExStyle">#1</a>: Removes the active window's title bar (WS_CAPTION):</p>
<pre>WinSetStyle "-0xC00000", "A"</pre>
</div>

<div class="ex" id="ExExStyle">
<p><a href="#ExExStyle">#2</a>: Toggles the WS_EX_TOOLWINDOW attribute, which removes/adds Notepad from the alt-tab list:</p>
<pre class="NoIndent">WinSetExStyle "^0x80", "ahk_class Notepad"</pre>
</div>

</body>
</html>